package com.sooncode.project.focusservice.controller;

import com.sooncode.project.core.finder.Page;
import com.sooncode.project.focusservice._.base.Utils;
import com.sooncode.project.focusservice.model.Teacher;
import com.sooncode.project.focusservice.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("teacher")
public class TeacherController {
    @Autowired
    TeacherService service;

    @PostMapping("teacher")
    public boolean add(@RequestParam Map map){
        return service.add(map);
    }
    @PutMapping("teacher")
    public boolean modify(@RequestParam String id,@RequestParam Map map){
        return service.modify(id,map);
    }
    @DeleteMapping("teacher")
    public boolean delete(@RequestParam String[] ids){
        for (String id:ids){
            service.delete(id);
        }
        return true;
    }
    @GetMapping("teachers")
    public Page<Teacher> getPageList(@RequestParam int pageSize, @RequestParam int pageIndex, @RequestParam Map map) {
        map.remove("pageSize");
        map.remove("pageIndex");
        map.remove("memberId");
        Utils.mapValueTrim(map);
        return service.getPageList(pageSize, pageIndex-1, map);
    }
    @GetMapping("teacherList/byOrgId")
    public List<Teacher> getList(@RequestParam String orgId){
        Map<String,String> map=new HashMap<>();
        map.put("orgId",orgId);
        return service.getList(map);
    }
    @GetMapping("teachers/byOrgId")
    public Page<Teacher> getPageList(@RequestParam String orgId,@RequestParam int pageSize, @RequestParam int pageIndex, @RequestParam Map map) {
        map.remove("pageSize");
        map.remove("pageIndex");
        map.remove("orgId");
        Utils.mapValueTrim(map);
        return service.getPageList(orgId,pageSize, pageIndex-1, map);
    }
}
